module majiang.Views {
    /**
     * 待选区
     */
    export class XuanArea extends eui.Component {
        //eui
        public paiGroup:eui.Group;

        constructor(parameters) {
            super();
        }

        /**
         * initXuanArea
         */
        public initXuanArea() {
            var index:number = majiang.Datas.Playing.xuanIndexMax;
            for (var i = 0; i < this.paiGroup.numChildren; i++) {
                var element:majiang.Views.MajiangBtn = <majiang.Views.MajiangBtn> this.paiGroup.getChildAt(i);

                if(i >= index){
                    element.setMajingpai(0,"gai","xuan");
                }else{
                    element.setMajingpai(22,"li","xuan");
                }   
            }
        }

        /**
         * gameStart
         */
        public gameStart() {
            this.initXuanArea();
        }

        /**
         * removeMajiang
         * 移除一张选中的牌
         */
        public removeMajiang(pai:majiang.Views.MajiangBtn) {
            this.paiGroup.removeChild(pai);
        }

        /**
         * addMajiang
         * 增加一张麻将牌到结尾
         */
        public addMajiang(pai:majiang.Views.MajiangBtn) {
            this.paiGroup.addChild(pai);
        }

        /**
         * openNextGaipai
         * 翻起下一张盖牌
         */
        public openNextGaipai() {
            for (var index = 0; index < this.paiGroup.numChildren; index++) {
                var element:majiang.Views.MajiangBtn = <majiang.Views.MajiangBtn> this.paiGroup.getChildAt(index);
                if(element.getCurrentState() === "gai"){
                    element.openGaipai();
                    return
                }
            }
        }
    }
}